package com.youkeyi.ddy.cloud.common.utils;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;

import javax.crypto.Cipher;
import java.io.ByteArrayOutputStream;
import java.net.URLDecoder;
import java.security.*;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  加密方式
 * </p>
 *
 * @author 23.1
 * @since 2020-05-11
 */
public class SecurityUtils {
	private static final String KEY_ALGORITHM = "RSA";
	private static final String RSA_MODE = "RSA/ECB/PKCS1Padding";
	private static final String SIGNATURE_ALGORITHM = "MD5withRSA";
	private static final String PUBLIC_KEY = "RSAPublicKey";
	private static final String PRIVATE_KEY = "RSAPrivateKey";
	/**
	 * 密钥长度（bit）
	 */
	private static final int KEY_LENGTH = 1024;
	/**
	 * RSA最大加密明文大小
	 */
	private static final int MAX_ENCRYPT_BLOCK = 117;
	/**
	 * RSA最大解密密文大小
	 */
	private static final int MAX_DECRYPT_BLOCK = 128;

	/**
	 * 用私钥对信息生成数字签名
	 * 
	 * @param data       加密数据
	 * @param privateKey 私钥
	 * @return
	 * @throws Exception
	 */
	public static String sign(byte[] data, String privateKey) throws Exception {
		// 解密由base64编码的私钥
		byte[] keyBytes = decryptBASE64(privateKey);

		// 构造PKCS8EncodedKeySpec对象
		PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes);

		// KEY_ALGORITHM 指定的加密算法
		KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);

		// 取私钥匙对象
		PrivateKey priKey = keyFactory.generatePrivate(pkcs8KeySpec);

		// 用私钥对信息生成数字签名
		Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM);
		signature.initSign(priKey);
		signature.update(data);

		return encryptBASE64(signature.sign());
	}

	/**
	 * 用私钥对信息生成数字签名
	 * 
	 * @param data       加密数据
	 * @param privateKey 私钥
	 * @return
	 * @throws Exception
	 */
	public static String sign(String data, String privateKey) throws Exception {
		return sign(data.getBytes(), privateKey);
	}

	/**
	 * 校验数字签名
	 * 
	 * @param data      加密数据
	 * @param publicKey 公钥
	 * @param sign      数字签名
	 * @return 校验成功返回true 失败返回false
	 * @throws Exception
	 */
	public static boolean verify(byte[] data, String publicKey, String sign) throws Exception {

		// 解密由base64编码的公钥
		byte[] keyBytes = decryptBASE64(publicKey);

		// 构造X509EncodedKeySpec对象
		X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);

		// KEY_ALGORITHM 指定的加密算法
		KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);

		// 取公钥匙对象
		PublicKey pubKey = keyFactory.generatePublic(keySpec);

		Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM);
		signature.initVerify(pubKey);
		signature.update(data);

		// 验证签名是否正常
		return signature.verify(decryptBASE64(sign));
	}

	/**
	 * 校验数字签名
	 * 
	 * @param data      加密数据
	 * @param publicKey 公钥
	 * @param sign      数字签名
	 * @return 校验成功返回true 失败返回false
	 * @throws Exception
	 */
	public static boolean verify(String data, String publicKey, String sign) throws Exception {
		return verify(data.getBytes(), publicKey, sign);
	}

	/**
	 * 将base 64 code RSA私钥解密
	 * 
	 * @param encryptStr 待解密的base 64 code
	 * @param decryptKey 解密密钥
	 * @return 解密后的string
	 * @throws Exception
	 */
	public static String rsaDecryptByPrivateKey(String encryptStr, String decryptKey) throws Exception {
		String rsaDecryptResult = null;
		if (StringUtils.isNotBlank(encryptStr)) {
			rsaDecryptResult = decryptByPrivateKey(decryptBASE64(encryptStr), decryptKey);
		}
		return rsaDecryptResult;
	}

	/**
	 * 将base 64 code RSA公钥解密
	 * 
	 * @param encryptStr 待解密的base 64 code
	 * @param decryptKey 解密密钥
	 * @return 解密后的string
	 * @throws Exception
	 */
	public static String rsaDecryptByPublicKey(String encryptStr, String decryptKey) throws Exception {
		String rsaDecryptResult = null;
		if (StringUtils.isNotBlank(encryptStr)) {
			rsaDecryptResult = decryptByPublicKey(decryptBASE64(encryptStr), decryptKey);
		}
		return rsaDecryptResult;
	}

	/**
	 * 解密<br>
	 * 用私钥解密
	 * 
	 * @param data
	 * @param key
	 * @return
	 * @throws Exception
	 */
	private static String decryptByPrivateKey(byte[] data, String key) throws Exception {
		RSAPrivateKey privateKey = (RSAPrivateKey) getPrivateKey(key);
		// 对数据解密
		Cipher cipher = Cipher.getInstance(RSA_MODE);
		cipher.init(Cipher.DECRYPT_MODE, privateKey);
		int inputLen = data.length;
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		int offset = 0;
		byte[] cache;
		int i = 0;
		// 对数据分段加密
		while (inputLen - offset > 0) {
			if (inputLen - offset > MAX_DECRYPT_BLOCK) {
				cache = cipher.doFinal(data, offset, MAX_DECRYPT_BLOCK);
			} else {
				cache = cipher.doFinal(data, offset, inputLen - offset);
			}
			out.write(cache, 0, cache.length);
			i++;
			offset = i * MAX_DECRYPT_BLOCK;
		}
		byte[] decryptBytes = out.toByteArray();
		out.close();
		return new String(decryptBytes);
	}

	/**
	 * 解密<br>
	 * 用公钥解密
	 * 
	 * @param data
	 * @param key
	 * @return
	 * @throws Exception
	 */
	private static String decryptByPublicKey(byte[] data, String key) throws Exception {
		RSAPublicKey publicKey = (RSAPublicKey) getPublicKey(key);

		// 对数据解密
		Cipher cipher = Cipher.getInstance(RSA_MODE);
		cipher.init(Cipher.DECRYPT_MODE, publicKey);

		int inputLen = data.length;
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		int offset = 0;
		byte[] cache;
		int i = 0;
		// 对数据分段加密
		while (inputLen - offset > 0) {
			if (inputLen - offset > MAX_DECRYPT_BLOCK) {
				cache = cipher.doFinal(data, offset, MAX_DECRYPT_BLOCK);
			} else {
				cache = cipher.doFinal(data, offset, inputLen - offset);
			}
			out.write(cache, 0, cache.length);
			i++;
			offset = i * MAX_DECRYPT_BLOCK;
		}
		byte[] decryptBytes = out.toByteArray();
		out.close();
		return new String(decryptBytes);
	}

	/**
	 * RSA公钥加密为base 64 code
	 * 
	 * @param content    待加密的内容
	 * @param encryptKey 加密密钥
	 * @return 加密后的base 64 code
	 * @throws Exception
	 */
	public static String rsaEncryptyPublicKey(String content, String encryptKey) throws Exception {
		return encryptBASE64(rasEncryptByPublicKeyToBytes(content, encryptKey));
	}

	/**
	 * RSA私钥加密为base 64 code
	 * 
	 * @param content    待加密的内容
	 * @param encryptKey 加密密钥
	 * @return 加密后的base 64 code
	 * @throws Exception
	 */
	public static String rsaEncryptyPrivateKey(String content, String encryptKey) throws Exception {
		return encryptBASE64(rasEncryptByPrivateKeyToBytes(content, encryptKey));
	}

	/**
	 * 加密<br>
	 * 用公钥加密
	 * 
	 * @param data
	 * @param key
	 * @return
	 * @throws Exception
	 */
	private static byte[] rasEncryptByPublicKeyToBytes(String data, String key) throws Exception {
		byte[] dataBytes = data.getBytes();
		RSAPublicKey publicKey = (RSAPublicKey) getPublicKey(key);

		// 对数据加密
		Cipher cipher = Cipher.getInstance(RSA_MODE);
		cipher.init(Cipher.ENCRYPT_MODE, publicKey);
		int inputLen = dataBytes.length;
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		int offset = 0;
		byte[] cache;
		int i = 0;
		// 对数据分段加密
		while (inputLen - offset > 0) {
			if (inputLen - offset > MAX_ENCRYPT_BLOCK) {
				cache = cipher.doFinal(dataBytes, offset, MAX_ENCRYPT_BLOCK);
			} else {
				cache = cipher.doFinal(dataBytes, offset, inputLen - offset);
			}
			out.write(cache, 0, cache.length);
			i++;
			offset = i * MAX_ENCRYPT_BLOCK;
		}
		byte[] decryptBytes = out.toByteArray();
		out.close();
		return decryptBytes;
	}

	/**
	 * 加密<br>
	 * 用私密加密
	 * 
	 * @param data
	 * @param key
	 * @return
	 * @throws Exception
	 */
	private static byte[] rasEncryptByPrivateKeyToBytes(String data, String key) throws Exception {
		byte[] dataBytes = data.getBytes();
		RSAPrivateKey privateKey = (RSAPrivateKey) getPrivateKey(key);

		// 对数据加密
		Cipher cipher = Cipher.getInstance(RSA_MODE);
		cipher.init(Cipher.ENCRYPT_MODE, privateKey);
		int inputLen = dataBytes.length;
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		int offset = 0;
		byte[] cache;
		int i = 0;
		// 对数据分段加密
		while (inputLen - offset > 0) {
			if (inputLen - offset > MAX_ENCRYPT_BLOCK) {
				cache = cipher.doFinal(dataBytes, offset, MAX_ENCRYPT_BLOCK);
			} else {
				cache = cipher.doFinal(dataBytes, offset, inputLen - offset);
			}
			out.write(cache, 0, cache.length);
			i++;
			offset = i * MAX_ENCRYPT_BLOCK;
		}
		byte[] decryptBytes = out.toByteArray();
		out.close();
		return decryptBytes;
	}

	/**
	 * 取得私钥
	 * 
	 * @param keyMap
	 * @return
	 * @throws Exception
	 */
	public static String getPrivateKey(Map<String, Object> keyMap) throws Exception {
		Key key = (Key) keyMap.get(PRIVATE_KEY);
		return encryptBASE64(key.getEncoded());
	}

	/**
	 * 取得公钥
	 * 
	 * @param keyMap
	 * @return
	 * @throws Exception
	 */
	public static String getPublicKey(Map<String, Object> keyMap) throws Exception {
		Key key = (Key) keyMap.get(PUBLIC_KEY);

		return encryptBASE64(key.getEncoded());
	}

	/**
	 * 初始化密钥 -生成rsa的公钥和私钥、最小长度为KEY_LENGTH
	 * 
	 * @return
	 * @throws Exception
	 */
	public static Map<String, Object> initKey(int length) throws Exception {
		KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM);
		keyPairGen.initialize(length);

		KeyPair keyPair = keyPairGen.generateKeyPair();

		// 公钥
		RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();

		// 私钥
		RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();

		Map<String, Object> keyMap = new HashMap<String, Object>(2);

		keyMap.put(PUBLIC_KEY, publicKey);
		keyMap.put(PRIVATE_KEY, privateKey);
		return keyMap;
	}

	/**
	 * 初始化密钥 -生成rsa的公钥和私钥、最小长度为KEY_LENGTH
	 * 
	 * @return
	 * @throws Exception
	 */
	public static Map<String, Object> initKey(int length, String seed) throws Exception {
		KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM);
		keyPairGen.initialize(length);
		if (StringUtils.isNotBlank(seed)) {
			keyPairGen.initialize(length, new SecureRandom(seed.getBytes()));
		} else {
			keyPairGen.initialize(length, new SecureRandom(String.valueOf(System.currentTimeMillis()).getBytes()));
		}
		KeyPair keyPair = keyPairGen.generateKeyPair();

		// 公钥
		RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();

		// 私钥
		RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();

		Map<String, Object> keyMap = new HashMap<String, Object>(2);

		keyMap.put(PUBLIC_KEY, publicKey);
		keyMap.put(PRIVATE_KEY, privateKey);
		return keyMap;
	}

	/**
	 * BASE64解密
	 * 
	 * @param key
	 * @return
	 * @throws Exception
	 */
	public static byte[] decryptBASE64(String key) throws Exception {
		return StringUtils.isBlank(key) ? null : Base64.decodeBase64(key.getBytes());
	}

	/**
	 * BASE64 加密
	 * 
	 * @param key
	 * @return
	 * @throws Exception
	 */
	public static String encryptBASE64(byte[] key) throws Exception {
		return new String(Base64.encodeBase64(key));
	}

	/****************************************
	 * 函数说明：getPublicKey 取得公钥
	 *
	 * @param key 公钥字符串
	 * @throws Exception
	 * @return PublicKey 返回公钥
	 * @author zhangmin
	 ***************************************/
	public static PublicKey getPublicKey(String key) throws Exception {
		byte[] keyBytes = decryptBASE64(key);

		X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
		KeyFactory keyFactory = KeyFactory.getInstance("RSA");
		PublicKey publicKey = keyFactory.generatePublic(keySpec);
		return publicKey;
	}

	/****************************************
	 * 函数说明：getPrivateKey 取得私钥
	 *
	 * @param key 私钥字符串
	 * @throws Exception
	 * @return PrivateKey 返回私钥
	 * @author zhangmin
	 ***************************************/
	public static PrivateKey getPrivateKey(String key) throws Exception {
		byte[] keyBytes = decryptBASE64(key);

		PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
		KeyFactory keyFactory = KeyFactory.getInstance("RSA");
		PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
		return privateKey;
	}

	/**
	 * 返回一组密钥
	 * 
	 * @param seed
	 * @return
	 * @throws Exception
	 */
	public static SecurityKey getKey(String seed) throws Exception {
		Map<String, Object> initKeyMap = initKey(KEY_LENGTH, seed);
		String privateKey = getPrivateKey(initKeyMap);
		String publicKey = getPublicKey(initKeyMap);
		return new SecurityKey(publicKey, privateKey);
	}
	
	/**
	 * 生成MD5码
	 * 
	 * @param text
	 * @param salt
	 * @return
	 */
	public static String md5(String text, String salt) {
		if (!StringUtils.isBlank(text)) {
			try {
				MessageDigest m = MessageDigest.getInstance("MD5");
				m.update(String.format("%s%s", text, salt).getBytes("UTF8"));
				byte s[] = m.digest();
				String result = "";
				for (int i = 0; i < s.length; i++) {
					result += Integer.toHexString((0x000000FF & s[i]) | 0xFFFFFF00).substring(6);
				}
				return result;
			} catch (Exception e) {
				e.printStackTrace();
			} 
		}
		return null;
	}
	
	/**
	 * MD5密文生成器
	 * 
	 * @param text
	 * @param salt
	 * @return
	 * @throws Exception
	 */
    public static String encryptText(String text, String salt) throws Exception {
    	try {
            StringBuilder md5Code = new StringBuilder();
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            text = text + "{" + salt + "}";
            byte[] digest = md5.digest(text.getBytes());
            for (byte b : digest) {
                md5Code = md5Code.append(byteToString(b));
            }
            return md5Code.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
    
    private static String byteToString(byte ss) {
        final String[] goal = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
        int temp;
        temp = ss < 0 ? ss + 256 : ss;
        return goal[temp / 16] + goal[temp % 16]; // 自己实现转化
    }

	public static class SecurityKey {
		private String publicKey;
		private String privateKey;

		SecurityKey(String publicKey, String privateKey) {
			this.publicKey = publicKey;
			this.privateKey = privateKey;
		}

		public String getPublicKey() {
			return publicKey;
		}

		public void setPublicKey(String publicKey) {
			this.publicKey = publicKey;
		}

		public String getPrivateKey() {
			return privateKey;
		}

		public void setPrivateKey(String privateKey) {
			this.privateKey = privateKey;
		}
	}

	public static void main(String[] args) throws Exception {
		String text = "lsdalkfgPS:RSA加密对明文的长度有所限制，规定需加密的明文最大长度=密钥长度-11（单位是字节，即byte），所以在加密和解密的过程中需要分块进行。而密钥默认是1024位，即1024位/8位-11=128-11=117字节。所以默认加密前的明文最大长度117字节，解密密文最大长度为128字。那么为啥两者相差11字节呢？是因为RSA加密使用到了填充模式（padding），即内容不足117字节时会自动填满，用到填充模式自然会占用一定的字节，而且这部分字节也是参与加密的";
		SecurityKey key = getKey("HelloWorld");
		String publicKey = key.getPublicKey();
		String privateKey = key.getPrivateKey();
		String rsaEncryptyPrivateKey = rsaEncryptyPrivateKey(text, privateKey);
		String rsaEncryptyPublicKey = rsaEncryptyPublicKey(text, publicKey);
		System.out.println("PK: " + privateKey);
		System.out.println("PUK: " + publicKey);
		System.out.println(rsaEncryptyPrivateKey);
		System.out.println(rsaEncryptyPublicKey);
		System.out.println(rsaDecryptByPrivateKey(rsaEncryptyPublicKey, privateKey));
		System.out.println(rsaDecryptByPublicKey(rsaEncryptyPrivateKey, publicKey));
		String sign = sign(text.getBytes(), privateKey);
		System.out.println(sign);
		System.out.println(verify(text.getBytes(), publicKey, sign));
		System.out.println("================================>");
		SecurityKey securityKey = SecurityUtils.getKey(String.valueOf(System.currentTimeMillis()));
		System.out.println("Public Key: " + securityKey.getPublicKey());
		System.out.println("Private Key: " + securityKey.getPrivateKey());
		System.out.println(rsaEncryptyPrivateKey(text, privateKey));
		System.out.println(rsaEncryptyPrivateKey(text, privateKey));
		System.out.println(rsaEncryptyPrivateKey(text, privateKey));
		
		String content = "{\"loginMode\":3,\"ip\":\"127.0.0.1\",\"password\":\"1\",\"account\":\"hoshino\"}";
		publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCK03lyc2DFkh6WyK2HomsBeAicC1WIhmXkME/9XwrqRnwNTAqHB4iKrVgGhD8asAy9KlxgwEgh3UtMDSiYoByDt68yySp9UEm++bDDyBopwiTioPQops9sX28Z3m7P3w8wgu+AP9VV5n6OOapDmjLe3MFGML5fiMgiiATyur18iQIDAQAB";
		System.out.println(rsaEncryptyPublicKey(content, publicKey));
		
		publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCHMzkK/N/42CfFV9TfCLUcmaiBTn7pAxqte2plyb3lFNTYGWx7Wy8GmQZ7NuUBg8fCqDhA4iw+Riw6sIi1RFSwx3Gv7OWX3UzC/PstE7HyqWih6jRa2evD8E4Rn503yBjjghNUcmuH/vDG0tk3U/sODHLwjCs4nhbc1Um2Q4A6dwIDAQAB";
		content = "{\"mac\":[\"8CFCA004D263\",\"8CFCA004D265\"]}";
		System.out.println(rsaEncryptyPublicKey(content, publicKey));
		
		publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQClHZzOhDWsNVN6RzTiubR1am1F1qsa7pgzsYCS7JahBJCSZPxS9i0S6NBcIuueMptPcl0mg/mv2azeqnRID+9EL8zOROO/s0POVgFwmsJrO/hAqXjeIger7DoDf7jMRzlW/ZcYx0SAEhG2HrWvEPYz6PJyIBFPu29Lom/bYrxElwIDAQAB";
		content = "{\"account\":\"YJL2020111330\",\"password\":\"123456\",\"phone\":\"18888888888\",\"nickname\":\"YJL2020111330\"}";
		System.out.println(rsaEncryptyPublicKey(content, publicKey));
		
		publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCoPNJGAtTRsFvo6HJ0PqkxVv5N/m6F6HE8NX40MEFB3HbxL9aaXnFAJEzlSPa9TpVpfN9y/8aX93z/mSCMabxw8cNF4ARsVsE0WIRTEi7+xnj24+t1/CxAvS0RBOmSURJLKeY6AgUHzsTpzRhzDQo+FlZLG3eF8mIB632LlLytvwIDAQAB";
		content = "{\"account\":\"TEST\",\"password\":\"123456\",\"email\":\"18888888888@qq.com\",\"validateCode\":\"hOYyche\"}";
		System.out.println(rsaEncryptyPublicKey(content, publicKey));
		
		publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCd4FC9Qu25HJqbFsHx1DmjCTWHT3KNq7IvBRNvdNBecNkMylqitgjEvd2VyuRXxrku/3qoCylgW2FykZWxaP1qez69ES2qGKeUQtM8C1mbJmbA46jDmkLzywiT7Fb+pNBXsTyvmeoHPhqopjs0GI4wMc4oY6w+yZuvXG0+ebaDkQIDAQAB";
		privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJ3gUL1C7bkcmpsWwfHUOaMJNYdPco2rsi8FE2900F5w2QzKWqK2CMS93ZXK5FfGuS7/eqgLKWBbYXKRlbFo/Wp7Pr0RLaoYp5RC0zwLWZsmZsDjqMOaQvPLCJPsVv6k0FexPK+Z6gc+GqimOzQYjjAxzihjrD7Jm69cbT55toORAgMBAAECgYA7l8qiRjs5nqR1WjfHMta2xekgtEqHU4Ik4YOelLd6jpo/i7p+pLvWl9ymiDl9MJQCO4lvGRd7OcMk3fNlTj4pdUOvU4tljs+YGovKmadg8BOFlKdQPajcGTx6PWmqFCNFZSvZOncvPovSsgu89dAA7wTZWL+w+ekKC6bQxtu8gQJBANgwuFiFLMojS0utiGDv6597Wo9PEIAvOL6mUAib0ie2PPmoSyzaSIzyM3FJbeLEGuQsjiF0Zb8yfLvl/QW3uIkCQQC68qapcD6dF0khKb8d5tq6I72AxwLrdM04IZJ0xqpzu6YF/MM8O7VHGJdWXY2mbsLA37XPdrpUoT7UwieV2aDJAkEAsYaQWmBBf1usIODG9JMPMU7h9nw+WIRuXF/FqMwLroB/YaNI1/QHT3Yzt/tMOMJAMs5DiEVEp9SViNY7B87twQJAeh4rlB8IJ6GgWZNljmjQlCrojQhy9c+UhogXnURw76yyJNMZzWzLW6fKo9X0w7Uybr8zilPqH4I9AsnZBd/lUQJAYWfehXJVO6XaCLwDk1SdFzJZeMHoZw89l6+tEtvNFspHh3EbfIc8pfl/p68+UEXlp2dd91wAdTjhN9WJJLnlCQ==";
		content = "{\"account\":\"金飞达看廖鸡\",\"password\":\"123123\",\"confirmPassword\":\"123123\",\"remark\":\"快递费金卡\"}";
		String te = rsaEncryptyPublicKey(content, publicKey);
		System.out.println(te);
		System.out.println(rsaDecryptByPrivateKey(te, privateKey));
		
		privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMPMvPvsaHbwpt3fNFwMasDhbZkZ9QidDOsNwJmtzWj2mO25uDFg0ftma2ZdnPXPFrUYxpKuV1wb3tcmdt8bEhadmxtWuMj+jIktw1sw+3njsI3DMgk/GQH+FhB/7E7I2DB+G6qjWW0ZQ3gclLloiaXyelfmKaWp9fJ8Tz7aA8R/AgMBAAECgYAVYqlJgrquMv6mwRhA7YJDatvDmxguRqkAi1H79wW2byio3l4F1qNYqAkW9yaLmoDKathVcQFNqCWgrizRlW1WJcnr5+0Bm+daiRTazxx8gkfz9Kim7WRjJofRlBV76rzUi9+hVz69ttFw+0XA0pZDNKwVXxyLniEArCOAGtaB0QJBAPshGhPaVVfdPMwqL1APsYX+jOfMWXaYnSXGD20dx+p2S/jooiJxljosq+QWdfbm8m9tuwlDYCyN5bECyk9BNfsCQQDHmOqFSUKfI81nILi4GoEYp2ifb0lID6VUqmmCI25TlzT27FHcPpGl0zXqABWCsShIx3F5VcIRcq3VzqDOVRhNAkB0hAQ8Z9WnAZ/+vifbhpyAJf2sYrSzgNWQvBdWMjYaQ662GwF256qi7S0Hk6BB4R9ksc3Q23DY2zFR8pB5OzFXAkARa69MYtCFw0IyNhDpQKbz1+ixwazLtVHgyd7blOwUL6ZXxth+OJfNuVmDSu6VsZCqiX3F8U4256N0fcxbNeIhAkEAuTHcL1EAcFGjF6tEgZcYKDVEk+AuT7HSEYCFLZH0R7vViNU3PhAbUuAwWQZvYlG8MEV7P4OAT7Ur4H87q6BHbA==";
		content = "mtEALEatgE+FigcxygP9NYBnS2wHik4Im1va6Cd9fXwmN/Vg1abCHHwEOgkfRByLgLL9C1Unc3T22Ek/LKfBWufF0a72aqfyEKP34rNAizPVpfmmfwWHZZTCKeEhFrJRnVcZM7rTVZCor6BQsaTQq3tjj7nzCcByb7wt0Frkgic=";
		System.out.println(rsaDecryptByPrivateKey(content, privateKey));
		
		System.out.println(md5("123456", "19e626cb8df64f99a096df80386699op"));
		
		System.out.println(encryptText("123", "efb5fcde2d6141cc95b4a309bdf04f6c"));
		
		System.out.println(URLDecoder.decode("%7B%22account%22%3A%22%E5%B0%8F%E7%99%BD%E9%BE%99%22%2C%22password%22%3A%22123%22%2C%22confirmPassword%22%3A%22123%22%2C%22remark%22%3A%22%E5%A4%87%E6%B3%A8%E4%B8%80%E4%B8%8B%22%2C%22nickname%22%3A%22%E5%B0%8F%E7%99%BD%E9%BE%99%22%7D","UTF-8"));
	}
}
